﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.HttpsPolicy;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using WeShare.WeiXin.Common;
using WeShare.WeiXin.Common.EnumKey;

namespace WebApp
{
    public class Startup
    {
        public Startup(IConfiguration configuration)
        {
            Configuration = configuration;
        }

        public IConfiguration Configuration { get; }

        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            DateTime dt = DateTime.Now;
            var csredis = new CSRedis.CSRedisClient("127.0.0.1:6379");
            CultureInfo.DefaultThreadCurrentCulture = CultureInfo.CreateSpecificCulture("zh-CN");
            RedisHelper.Initialization(csredis);
            var dt1 = DateTime.Now;
            var wxapi = new OpenApi(new CustomerRedis());
            wxapi.RegisterAsync(
                new ApiConfig { AppId = "wx891ee9903ba8d74e", AppSecret = "c286dcbdd64a50769b2803b52ee9630e", Platform = PlatformType.Mp });
            wxapi.RegisterPay(new PayConfig { AppId = "wx891ee9903ba8d74e", CertPath = @"C:\Users\billsking\Downloads\WXCertUtil\WXCertUtil-1.1\cert\1240050702_20181222_cert\apiclient_cert.p12", MchId = "1240050702", PayKey = "c4115c3cbb9e4f64b3d0cfb726e06001" });
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
        }

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseHsts();
            }
            app.UseStaticFiles();
            app.UseHttpsRedirection();
            app.UseMvc();
        }
    }
}
